package com.heima.reggie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.heima.reggie.bean.SetmealDish;
import com.heima.reggie.mapper.SetmealDishMapper;
import com.heima.reggie.service.SetmealDishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SetmealDishServiceImpl implements SetmealDishService {
    @Autowired
    private SetmealDishMapper mapper;
   /**
     * 新增
     * @param
     * @param
     * @return
     */
    @Override
    public int add(SetmealDish setmealDish) {
        return mapper.insert(setmealDish);
    }
/**
  * 根据套餐id删除
  * @param
  * @param
  * @return
  */
    @Override
    public int deleteBySid(long sid) {
        LambdaQueryWrapper<SetmealDish> lqw = new LambdaQueryWrapper<>();
        lqw.eq(SetmealDish::getSetmealId, sid);
        return mapper.delete(lqw);
    }
/**
  * 根据套餐id统计套餐菜品数量
  * @param
  * @param
  * @return
  */
    @Override
    public int countBySid(long sid) {
        LambdaQueryWrapper<SetmealDish> lqw = new LambdaQueryWrapper<>();
        lqw.eq(SetmealDish::getSetmealId, sid);
        return mapper.selectCount(lqw);
    }
/**
  * 根据套餐id查询套餐菜品
  * @param
  * @param
  * @return
  */
    @Override
    public List<SetmealDish> selectBySid(long sid) {
        LambdaQueryWrapper<SetmealDish> lqw = new LambdaQueryWrapper<>();
        lqw.eq(SetmealDish::getSetmealId, sid);
        return mapper.selectList(lqw);
    }
/**
  * 根据菜品id查询套餐菜品
  * @param
  * @param
  * @return
  */
    @Override
    public List<SetmealDish> selectByDid(long did) {
        LambdaQueryWrapper<SetmealDish> lqw = new LambdaQueryWrapper<>();
        lqw.eq(SetmealDish::getDishId,did);
        return mapper.selectList(lqw);
    }

}
